﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

namespace MoFramework
{
    public class UIItemSlotGrid : UIItemSlotLayoutBase
    {
        List<UIItemSlotBase> m_TotalSlots= new List<UIItemSlotBase>();
        List<UIItemSlotBase> m_ShowingSlots = new List<UIItemSlotBase>();
        int m_TempIdx = 0;

        public override void Refresh()
        {
            foreach(var item in m_ShowingSlots)
            {
                item.gameObject.SetActive(false);
            }
            m_TempIdx = 0;
            foreach(var dat in proptyDatas)
            {
                var slot = GetUIItemSlot();
                slot.dat = dat;
                slot.Reset();
                m_ShowingSlots.Add(slot);
            }
        }
        UIItemSlotBase GetUIItemSlot()
        {
            if(m_TempIdx >= m_TotalSlots.Count) 
            {
                var obj = GameObject.Instantiate(m_Sample);
                obj.gameObject.SetActive(true);
                obj.transform.SetParent(transform, false);
                obj.gameObject.name = m_TempIdx.ToString();
                m_TotalSlots.Add(obj); 
            }
            return m_TotalSlots[m_TempIdx++];
        }
    }
}

